﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaSage.Lib.Client.Config;
using MediaSage.Lib.UIFramework.Dialog.Entities;
using MediaSage.Lib.Configuration;
using MediaSage.Lib.UIFramework.Theme;
using MediaSage.MCClient.Code.Themes;
using Microsoft.MediaCenter.UI;
using Microsoft.MediaCenter;
using Microsoft.MediaCenter.Hosting;

namespace MediaSage.Themes
{
    public class DefaultTheme : ThemeObject
    {
        private Guid activeDialog;

        /// <summary>
        /// Creates a dialog window
        /// </summary>
        /// <param name="dialogEntity"></param>
        /// <returns></returns>
        public override bool DialogWindow(Lib.UIFramework.Dialog.Entities.DialogMappingEntity dialogEntity)
        {
            logger.Log("Entering MediaSage.Themes.DialogWindow()");
            object[] dialogButtons=new object[dialogEntity.ResultOptions.Count];
            int a = 0;
            foreach (OptionEntity oe in dialogEntity.ResultOptions)
            {
                dialogButtons[a]=(String.Format("{0}{1}{2}",base.TextColor,base.TextFont,oe.OptionText));                
            }
            MediaCenterEnvironment mce = AddInHost.Current.MediaCenterEnvironment;
            int timeout = 0;
            if (dialogEntity.Timeout != null)
            {
                timeout = (int) dialogEntity.Timeout;
            }
            activeDialog = dialogEntity.ID;
            DialogResult result=mce.Dialog(String.Format("{0}{1}{2}",base.HeadingColor,base.H2Font,dialogEntity.MessageCaption),String.Format("{0}{1}{2}",base.TextColor,base.TextFont,dialogEntity.MessageText), dialogButtons, timeout,true,dialogEntity.DisplayGraphic,new DialogClosedCallback(dialogCallback));
            // Save the dialog result
            dialogEntity.DialogResult = result.ToString();
            dialogEntity.SaveOrUpdate();
            logger.Log("Exiting MediaSage.Themes.DialogWindow(), rc==true");            
            return true;
        }

        private void dialogCallback(DialogResult button)
        {
                
        }

        public override bool NotificationWindow(DialogMappingEntity dialogEntity)
        {
            logger.Log("Entering MediaSage.Themes.NotificationWindow()");
            object[] dialogButtons = new object[dialogEntity.ResultOptions.Count];
            int a = 0;
            foreach (OptionEntity oe in dialogEntity.ResultOptions)
            {
                dialogButtons[a] = (String.Format("{0}{1}{2}", base.TextColor, base.TextFont, oe.OptionText));
            }
            MediaCenterEnvironment mce = AddInHost.Current.MediaCenterEnvironment;
            int timeout = 0;
            if (dialogEntity.Timeout != null)
            {
                timeout = (int)dialogEntity.Timeout;
            }
            DialogResult result = mce.DialogNotification(String.Format("{0}{1}{2}", base.TextColor, base.TextFont, dialogEntity.MessageText), dialogButtons, timeout, dialogEntity.DisplayGraphic, new DialogClosedCallback(dialogCallback));
            // Save the dialog result
            dialogEntity.DialogResult = result.ToString();
            dialogEntity.SaveOrUpdate();
            logger.Log("Exiting MediaSage.Themes.NotificationWindow() rc==true");
            return true;
        }

        public DefaultTheme(Configuration config) :
            base(config)
        {
            base.initializeColors();
            base.initializeFonts();
            logger.Log("MediaSage.Themes.Default() initialized");
        }
    }
}
